Imports System 
Imports System.Text 
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.Common
Imports System.Collections
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Configuration 
Imports System.Xml 
Imports System.Xml.Serialization
Imports SubSonic 
Imports SubSonic.Utilities
Namespace Data
	''' <summary>
	''' Strongly-typed collection for the PlayersInStats class.
	''' </summary>
	<Serializable> _
	Public Partial Class PlayersInStatsCollection 
	Inherits ActiveList(Of PlayersInStats, PlayersInStatsCollection)
	    Public Sub New()
		End Sub
	End Class
	''' <summary>
	''' This is an ActiveRecord class which wraps the PlayersInStats table.
	''' </summary>
	<Serializable> _
	Public Partial Class PlayersInStats 
	Inherits ActiveRecord(Of PlayersInStats)
		#Region ".ctors and Default Settings"
		
		Public Sub New()
			SetSQLProps()
			InitSetDefaults()
			MarkNew()
		End Sub
		
		Public Sub New(ByVal useDatabaseDefaults As Boolean)
			SetSQLProps()
			If useDatabaseDefaults = True Then
				ForceDefaults()
			End If
			MarkNew()
		End Sub
		Public Sub New(ByVal keyID As Object)
			SetSQLProps()
			InitSetDefaults()
			LoadByKey(keyID)
		End Sub
		Public Sub New(ByVal columnName As String, ByVal columnValue As Object)
			SetSQLProps()
			InitSetDefaults()
			LoadByParam(columnName,columnValue)
		End Sub
		Private Sub InitSetDefaults()
			SetDefaults()
		End Sub
		
		Protected Shared Sub SetSQLProps()
			GetTableSchema()
		End Sub
		#End Region
		
		#Region "Schema and Query Accessor"
		
		Public Shared ReadOnly Property Schema() As TableSchema.Table
			Get
				If BaseSchema Is Nothing Then
					SetSQLProps()
				End If
				Return BaseSchema
			End Get
		End Property
		Private Shared Sub GetTableSchema()
			If (Not IsSchemaInitialized) Then
				'Schema declaration
				Dim schema As TableSchema.Table = New TableSchema.Table("PlayersInStats", TableType.Table, DataService.GetInstance("ClubStarterKitData"))
				schema.Columns = New TableSchema.TableColumnCollection()
				schema.SchemaName = "dbo"
				'columns
				
                
                Dim colvarId As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarId.ColumnName = "id"
                colvarId.DataType = DbType.Int32
                colvarId.MaxLength = 0
                colvarId.AutoIncrement = true
                colvarId.IsNullable = false
                colvarId.IsPrimaryKey = true
                colvarId.IsForeignKey = false
                colvarId.IsReadOnly = false
                
                
                schema.Columns.Add(colvarId)
                
                Dim colvarPlayerID As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarPlayerID.ColumnName = "PlayerID"
                colvarPlayerID.DataType = DbType.Int32
                colvarPlayerID.MaxLength = 0
                colvarPlayerID.AutoIncrement = false
                colvarPlayerID.IsNullable = false
                colvarPlayerID.IsPrimaryKey = false
                colvarPlayerID.IsForeignKey = true
                colvarPlayerID.IsReadOnly = false
                
                
				colvarPlayerID.ForeignKeyTableName = "Players"
                
                schema.Columns.Add(colvarPlayerID)
                
                Dim colvarGameid As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarGameid.ColumnName = "gameid"
                colvarGameid.DataType = DbType.Int32
                colvarGameid.MaxLength = 0
                colvarGameid.AutoIncrement = false
                colvarGameid.IsNullable = false
                colvarGameid.IsPrimaryKey = false
                colvarGameid.IsForeignKey = true
                colvarGameid.IsReadOnly = false
                
                
				colvarGameid.ForeignKeyTableName = "Games"
                
                schema.Columns.Add(colvarGameid)
                
                Dim colvarCatches As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarCatches.ColumnName = "Catches"
                colvarCatches.DataType = DbType.Int32
                colvarCatches.MaxLength = 0
                colvarCatches.AutoIncrement = false
                colvarCatches.IsNullable = true
                colvarCatches.IsPrimaryKey = false
                colvarCatches.IsForeignKey = false
                colvarCatches.IsReadOnly = false
                
                
                schema.Columns.Add(colvarCatches)
                
                Dim colvarRuns As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarRuns.ColumnName = "Runs"
                colvarRuns.DataType = DbType.Int32
                colvarRuns.MaxLength = 0
                colvarRuns.AutoIncrement = false
                colvarRuns.IsNullable = true
                colvarRuns.IsPrimaryKey = false
                colvarRuns.IsForeignKey = false
                colvarRuns.IsReadOnly = false
                
                
                schema.Columns.Add(colvarRuns)
                
                Dim colvarSaves As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarSaves.ColumnName = "Saves"
                colvarSaves.DataType = DbType.Int32
                colvarSaves.MaxLength = 0
                colvarSaves.AutoIncrement = false
                colvarSaves.IsNullable = true
                colvarSaves.IsPrimaryKey = false
                colvarSaves.IsForeignKey = false
                colvarSaves.IsReadOnly = false
                
                
                schema.Columns.Add(colvarSaves)
                
                Dim colvarInjured As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarInjured.ColumnName = "Injured"
                colvarInjured.DataType = DbType.Boolean
                colvarInjured.MaxLength = 0
                colvarInjured.AutoIncrement = false
                colvarInjured.IsNullable = true
                colvarInjured.IsPrimaryKey = false
                colvarInjured.IsForeignKey = false
                colvarInjured.IsReadOnly = false
                
                
                schema.Columns.Add(colvarInjured)
                
				BaseSchema = schema
				
				'add this schema to the provider
                'so we can query it later
                DataService.Providers("ClubStarterKitData").AddSchema("PlayersInStats",schema)
			End If
		End Sub
		Public Shared Function CreateQuery() As Query
			Return New Query(Schema)
		End Function
		
		#End Region
		
		#Region "Props"
	
          
        <XmlAttribute("Id")> _
        Public Property Id As Integer 
			Get
				Return GetColumnValue(Of Integer)("id")
			End Get
		    
			Set
				SetColumnValue("id", Value)
			End Set
		End Property
		
		
		  
        <XmlAttribute("PlayerID")> _
        Public Property PlayerID As Integer 
			Get
				Return GetColumnValue(Of Integer)("PlayerID")
			End Get
		    
			Set
				SetColumnValue("PlayerID", Value)
			End Set
		End Property
		
		
		  
        <XmlAttribute("Gameid")> _
        Public Property Gameid As Integer 
			Get
				Return GetColumnValue(Of Integer)("gameid")
			End Get
		    
			Set
				SetColumnValue("gameid", Value)
			End Set
		End Property
		
		
		  
        <XmlAttribute("Catches")> _
        Public Property Catches As Nullable(Of Integer) 
			Get
				Return GetColumnValue(Of Nullable(Of Integer))("Catches")
			End Get
		    
			Set
				SetColumnValue("Catches", Value)
			End Set
		End Property
		
		
		  
        <XmlAttribute("Runs")> _
        Public Property Runs As Nullable(Of Integer) 
			Get
				Return GetColumnValue(Of Nullable(Of Integer))("Runs")
			End Get
		    
			Set
				SetColumnValue("Runs", Value)
			End Set
		End Property
		
		
		  
        <XmlAttribute("Saves")> _
        Public Property Saves As Nullable(Of Integer) 
			Get
				Return GetColumnValue(Of Nullable(Of Integer))("Saves")
			End Get
		    
			Set
				SetColumnValue("Saves", Value)
			End Set
		End Property
		
		
		  
        <XmlAttribute("Injured")> _
        Public Property Injured As Nullable(Of Boolean) 
			Get
				Return GetColumnValue(Of Nullable(Of Boolean))("Injured")
			End Get
		    
			Set
				SetColumnValue("Injured", Value)
			End Set
		End Property
		
		
		
		
		#End Region
		
		
			    
	    
		
		
		
		
		
	    
	    #Region "ForeignKey Methods"
	    
		''' <summary>
		''' Returns a Games ActiveRecord object related to this PlayersInStats
		''' </summary>
		Public Property Games() As Data.Games
			Get
				Return Data.Games.FetchByID(Me.Gameid)
			End Get
			Set
				SetColumnValue("gameid", Value.Id)
			End Set
		End Property
	    
		''' <summary>
		''' Returns a Players ActiveRecord object related to this PlayersInStats
		''' </summary>
		Public Property Players() As Data.Players
			Get
				Return Data.Players.FetchByID(Me.PlayerID)
			End Get
			Set
				SetColumnValue("PlayerID", Value.Id)
			End Set
		End Property
	    
	    #End Region
	    
		
	    
	    'no ManyToMany tables defined (0)
	    
		
		#Region "ObjectDataSource support"
		
		''' <summary>
		''' Inserts a record, can be used with the Object Data Source
		''' </summary>
		Public Shared Sub Insert(ByVal varPlayerID As Integer,ByVal varGameid As Integer,ByVal varCatches As Nullable(Of Integer),ByVal varRuns As Nullable(Of Integer),ByVal varSaves As Nullable(Of Integer),ByVal varInjured As Nullable(Of Boolean))
			Dim item As PlayersInStats = New PlayersInStats()
			
            item.PlayerID = varPlayerID
            
            item.Gameid = varGameid
            
            item.Catches = varCatches
            
            item.Runs = varRuns
            
            item.Saves = varSaves
            
            item.Injured = varInjured
            
			If Not System.Web.HttpContext.Current Is Nothing Then
				item.Save(System.Web.HttpContext.Current.User.Identity.Name)
			Else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name)
			End If
		End Sub
		''' <summary>
		''' Updates a record, can be used with the Object Data Source
		''' </summary>
		Public Shared Sub Update(ByVal varId As Integer,ByVal varPlayerID As Integer,ByVal varGameid As Integer,ByVal varCatches As Nullable(Of Integer),ByVal varRuns As Nullable(Of Integer),ByVal varSaves As Nullable(Of Integer),ByVal varInjured As Nullable(Of Boolean))
			Dim item As PlayersInStats = New PlayersInStats()
		    
                item.Id = varId
				
                item.PlayerID = varPlayerID
				
                item.Gameid = varGameid
				
                item.Catches = varCatches
				
                item.Runs = varRuns
				
                item.Saves = varSaves
				
                item.Injured = varInjured
				
			item.IsNew = False
			If Not System.Web.HttpContext.Current Is Nothing Then
				item.Save(System.Web.HttpContext.Current.User.Identity.Name)
			Else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name)
			End If
		End Sub
		#End Region
		#Region "Columns Struct"
		Public Structure Columns
			Dim x as Integer
			
            Public Shared Id As String = "id"
            
            Public Shared PlayerID As String = "PlayerID"
            
            Public Shared Gameid As String = "gameid"
            
            Public Shared Catches As String = "Catches"
            
            Public Shared Runs As String = "Runs"
            
            Public Shared Saves As String = "Saves"
            
            Public Shared Injured As String = "Injured"
            
		End Structure
		#End Region
	End Class
End Namespace
